﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Parichay.Data.Helper;

namespace Parichay.Data.Repository
{
    public class LogRepository : Parichay.Domain.Interface.Data.ILogRepository
    {
        public void Log(Exception ex)
        {
            NHibernateHelper.Log(ex);
        }

        public void Log(object message, Domain.LogType logType)
        {
            NHibernateHelper.Log(message, logType);
        }


        public IList<Domain.Log> GetLogs(string loggerName, int pageSize, int pageIndex)
        {
            IList<Domain.Log> lstLogs = Data.Helper.NHibernateHelper.ConvertToListOf<Domain.Log>(Parichay.Data.Helper.NHibernateHelper.Find("select l from Log l where l.Logger=? order by l.Date desc", loggerName, NHibernate.NHibernateUtil.String, pageIndex, pageSize, false));
            return (lstLogs);
        }

        public void DeleteLog(int id)
        {
            Parichay.Data.Helper.NHibernateHelper.Delete<Parichay.Domain.Log>(Parichay.Data.Helper.NHibernateHelper.UniqueResult<Parichay.Domain.Log>(null, "Id", id));
        }
    }
}
